package net.uhuijia.user.userwxopen.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.uhuijia.appbase.service.CrudService;
import net.uhuijia.constants.DBConst;
import net.uhuijia.user.userwxopen.persistence.dao.UserWxopenDao;
import net.uhuijia.user.userwxopen.persistence.model.UserWxopen;
import net.uhuijia.user.userwxopen.persistence.model.UserWxopenExample;
import net.uhuijia.user.userwxopen.service.UserWxopenService;

@Service
@Transactional
public class UserWxopenServiceImpl extends CrudService<UserWxopenDao, UserWxopen, UserWxopenExample>
		implements UserWxopenService {

	@Override
	public UserWxopen getByUnionidAndGhid(String unionid, String ghid) {
		UserWxopen wxopen = new UserWxopen();
		wxopen.setIsEffective(DBConst.TRUE);
		wxopen.setUnionid(unionid);
		wxopen.setGhId(ghid);

		return mapper.getByUnionidAndGhid(wxopen);
	}

	@Override
	public String addWxopen(UserWxopen param) {
		UserWxopen wxopen = this.getByUnionidAndGhid(param.getUnionid(), param.getGhId());
		if (null == wxopen) {
			this.initDefalutFields(param);
			this.add(param);
		}
		return SUCCESS;
	}

}